package engine.step;

import engine.GameEngine;
import engine.UnitAction;
import engine.data.Player;

public final class NextUnitStep extends Step {

	private static Step step;

	public static synchronized Step getStep() {
		if (step == null)
			step = new NextUnitStep();
		return step;
	}

	public Step execute() {
		if (!GameEngine.currPlayer.nextUnit())
			return EndOfPlayerTurnStep.getStep();
		DoUnitActionStep.setAction(new UnitAction(GameEngine.currPlayer.controller.onBeginUnitTurn()));
		GameEngine.currPlayer.controller.onEndUnitTurn();
		if (GameEngine.currPlayer.type != Player.HUMAN)
			return DoUnitActionStep.getStep();
		return null;
	}
}
